package JiHeDemo;

import java.util.*;

public class TestMap1 {
	public static void a(String[] args) {
		HashMap<Integer, String> hmap = new HashMap();
		hmap.put(1, "我是一");
		hmap.put(2, "我是二");
		hmap.put(3, "我是三");
		hmap.put(4, "我是四");
		System.out.println(hmap.size());
		System.out.println(hmap);
		System.out.println("---使用KeySet---");
		Set<Integer> set = hmap.keySet();
		for (Integer s : hmap.keySet()) {
			System.out.println(s + "->" + hmap.get(s));
		}
		System.out.println("----使用entrySet---");
		Set<Map.Entry<Integer, String>> entry = hmap.entrySet();
		for (Map.Entry<Integer, String> e : entry) {
			System.out.println(e.getKey() + "=" + e.getValue());
		}
	}

	public static void main(String[] args) {
		HashMap<Student, String> map = new HashMap<>();
		ArrayList<Student> list = new ArrayList<>();
		ArrayList<Student> list1 = new ArrayList<>();
		Student s1 = new Student("唐僧", 10);
		Student s11 = new Student("李世民", 10);
		Student s2 = new Student("孙悟空", 88);
		Student s3 = new Student("猪八戒", 55);
		Student s4 = new Student("沙和尚", 34);
		list.add(s1);
		list.add(s11);
		System.out.println("list-->" + list);
		System.out.println("--------------------");
		System.out.println(Arrays.toString(list.toArray()));
		System.out.println("-------------------");
		Object[] a = list.toArray();
		System.out.println("list1-->" + list1);
		for (int i = 0; i < a.length; i++) {
			System.out.println(a[i]);
			list1.add((Student) a[i]);
		}
		System.out.println("list1-->" + list1);

		System.out.println("-------------------");
		map.put(s1, "大唐");
		map.put(s2, "五指山");
		map.put(s3, "高老庄");
		map.put(s4, "流沙河");
		System.out.println(map);
		System.out.println("使用KeySet方法遍历");
		for (Student obj : map.keySet()) {
			System.out.println(obj + "->" + map.get(obj));
		}
		System.out.println("使用entrySet遍历");
		for (Map.Entry<Student, String> e : map.entrySet()) {
			System.out.println(e.getKey() + "-->" + e.getValue());
		}
		System.out.println(map.containsKey(s1));
		System.out.println(map.containsKey(new Student("唐僧", 10)));
		System.out.println(map.containsValue("大唐"));
	}
}
